package com.jhs.boot.system.controller;

import com.jhs.boot.common.model.Option;
import com.jhs.boot.system.service.SysNodeRouteService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jhs.boot.system.model.form.SysNodeRouteForm;
import com.jhs.boot.system.model.query.SysNodeRouteQuery;
import com.jhs.boot.system.model.vo.SysNodeRouteVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jhs.boot.common.result.PageResult;
import com.jhs.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

import java.util.List;

/**
 * 节点和路由关联前端控制层
 *
 * @author zxy
 * @since 2025-11-22 11:28
 */
@Tag(name = "节点和路由关联接口")
@RestController
@RequestMapping("/api/v1/sys-node-route")
@RequiredArgsConstructor
public class SysNodeRouteController  {

    private final SysNodeRouteService sysNodeRouteService;

    @Operation(summary = "节点和路由关联分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('ap:sys-node-route:query')")
    public PageResult<SysNodeRouteVO> getSysNodeRoutePage(SysNodeRouteQuery queryParams ) {
        IPage<SysNodeRouteVO> result = sysNodeRouteService.getSysNodeRoutePage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增节点和路由关联")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('ap:sys-node-route:add')")
    public Result<Void> saveSysNodeRoute(@RequestBody @Valid SysNodeRouteForm formData ) {
        boolean result = sysNodeRouteService.saveSysNodeRoute(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取节点和路由关联表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('ap:sys-node-route:edit')")
    public Result<SysNodeRouteForm> getSysNodeRouteForm(
        @Parameter(description = "节点和路由关联ID") @PathVariable Long id
    ) {
        SysNodeRouteForm formData = sysNodeRouteService.getSysNodeRouteFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改节点和路由关联")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('ap:sys-node-route:edit')")
    public Result<Void> updateSysNodeRoute(
            @Parameter(description = "节点和路由关联ID") @PathVariable Long id,
            @RequestBody @Validated SysNodeRouteForm formData
    ) {
        boolean result = sysNodeRouteService.updateSysNodeRoute(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除节点和路由关联")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('ap:sys-node-route:delete')")
    public Result<Void> deleteSysNodeRoutes(
        @Parameter(description = "节点和路由关联ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = sysNodeRouteService.deleteSysNodeRoutes(ids);
        return Result.judge(result);
    }
}
